package cn.ococci.dm.Main.Core;

import com.alibaba.fastjson.Json;
import com.alibaba.fastjson.JsonObject;


import cn.ococci.dm.Main.Const;
import cn.ococci.dm.Main.Tools.LogTool;
import cn.ococci.dm.Main.Tools.StringTool;


/**
 * Created by cyan on 15/12/29.
 */
public class DecodeCommandUtils {

    public static final String TAG = DecodeCommandUtils.class.getSimpleName();


    /**
     * 判断当前设置白名单是否成功
     * @param json
     * @return
     */
    public static boolean isSetWhiteListSuccess(String json){

        if(StringTool.isEmpty(json)){
            return false;
        }

        JsonObject jsonObject = Json.parseObject(json);

        return jsonObject.containsKey(Const.BuilderParams.card_list);

    }

    /**
     * 获取固件的两个版本号
     * @param json
     * @return
     */
    public static String[] handlerOtaVersion(String json){

        String[] versions = new String[2];
        if(StringTool.isEmpty(json)){
            return versions;
        }

        JsonObject jsonObject = Json.parseObject(json);


        if(jsonObject.containsKey(Const.CommandParams.COMMAND_AP_VERSION)){

            versions[0] = jsonObject.getString(Const.CommandParams.COMMAND_AP_VERSION);

        }

        if(jsonObject.containsKey(Const.CommandParams.COMMAND_PR_VERSION)){

            versions[1] = jsonObject.getString(Const.CommandParams.COMMAND_PR_VERSION);
        }

        LogTool.log(TAG,"AP version:" + versions[0] + " ,pr version:" + versions[1]);

        return versions;
    }

    /**
     * 获取红外的状态
     * @param jsonStr
     * @return
     */
    public static boolean handlerInfraredResult(String jsonStr){

        JsonObject jsonObject =  Json.parseObject(jsonStr);

        if(jsonObject.containsKey(Const.CommandParams.COMMAND_INFRARED)){

            String status =  jsonObject.getString(Const.CommandParams.COMMAND_INFRARED);

            return status == Const.CommandParams.COMMAND_OPEN;
        }

        return false;

    }




}
